﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

/// <summary>
///jQClass 的摘要说明
/// </summary>
public class jQClass : Public.Common.Singleton.SingletonBase<jQClass>
{
    public jQClass()
    {
        count = 0;
        _temp = new _UpdateFangWen(UpdataFangWen);
    }


    int count = 0;
    string sql = @"select body_fangwen from forum_body where Body_ID={0}";
    DataSet ds;
    public int GetCount(int _ID)
    {
        count = 0;
        try
        {
            //count = Forum.Web.Repository.GetServices().forum_body.GetByBodyId(_ID).Body_FangWen.Value;
            ds = Forum.Providers.DataRepository.Provider.ExecuteDataSet(System.Data.CommandType.Text, string.Format(sql, _ID));
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                count = int.Parse(ds.Tables[0].Rows[0][0].ToString());
            }
        }
        catch
        {
        }
        _temp.BeginInvoke(_ID, count, null, null);
        return count;
    }

    string update = @"UPDATE forum_body set body_fangwen={1} where body_id={0}";
    public delegate void _UpdateFangWen(int _ID, int _count);
    _UpdateFangWen _temp;
    public void UpdataFangWen(int _ID, int _count)
    {
        try
        {
            //Forum.Entities.forum_bodyinfo model = Forum.Web.Repository.GetServices().forum_body.GetByBodyId(_ID);
            //model.Body_FangWen = model.Body_FangWen == null ? 1 : model.Body_FangWen.Value + 1;
            //Forum.Web.Repository.GetServices().forum_body.Update(model);

            Forum.Providers.DataRepository.Provider.ExecuteNonQuery(System.Data.CommandType.Text, string.Format(update, _ID,_count+1));
        }
        catch { }
    }

}